package com.example.controller;

import com.example.common.Result;
import com.example.entity.XueYuanInfo;
import com.example.service.XueyuanInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 涛某
 * @version 1.0
 * @date 2024/3/24 11:44
 */
@RestController
@RequestMapping("/xueyuanInfo")
public class XueyuanInfoController {
    @Autowired
   private XueyuanInfoService xueyuanInfoService;

    @GetMapping
    public Result finaAll(){
       List<XueYuanInfo> info = xueyuanInfoService.findAll();
        return Result.success(info);
    }
    @PostMapping
    public Result add(@RequestBody XueYuanInfo xueYuanInfo){
         xueyuanInfoService.add(xueYuanInfo);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody XueYuanInfo xueYuanInfo){
        xueyuanInfoService.update(xueYuanInfo);
        return Result.success();
    }
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable Long id){
        xueyuanInfoService.deleteById(id);
        return Result.success();
    }
    @GetMapping("/page")
    public Result fingPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        PageInfo<XueYuanInfo> info = xueyuanInfoService.findPage(pageNum,pageSize);
        return Result.success(info);
    }
    @GetMapping("/page/{search}")
    public Result findPage(@PathVariable() String search,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
       PageInfo<XueYuanInfo> list = xueyuanInfoService.findPageByName(search,pageNum,pageSize);
        return Result.success(list);
    }
}
